import instacne from "../request";
import type { Ref } from "vue";

/**
 * 分页查询后台菜单
 *
 */
interface IMenuListParams {
  parentId: number | Ref<number>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
}
export interface IMenuListRes {
  list: IMenuListItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}
interface IMenuListItem {
  createTime: string;
  email: string;
  icon: string;
  id: number;
  loginTime: string;
  nickName: string;
  note: string;
  password: string;
  status: number;
  username: string;
}
export const menuList = (data: IMenuListParams): Promise<IMenuListRes> =>
  instacne.get(`/menu/list/${data.parentId}`, {
    params: {
      pageNum: data?.pageNum,
      pageSize: data?.pageSize,
    },
  });
// 更新显示状态
export const updateHidden = (data: { id: number; hidden: boolean }) =>
  instacne.post(`/menu/updateHidden/${data.id}`, null, {
    params: {
      hidden: data.hidden,
    },
  });
// 根据ID获取菜单详情
export interface MenuData {
  createTime: string;
  hidden: number;
  icon: string;
  id: number;
  level: number;
  name: string;
  parentId: any;
  sort: any;
  title: string;
}
export const getMenuData = (id: number): Promise<MenuData> =>
  instacne.get(`/menu/${id}`);

// 添加后台菜单
export interface updataMenuData {
  hidden: number;
  icon: string;
  name: string;
  parentId: any;
  sort: any;
  title: string;
}
export const createMenu = (umsMenu: updataMenuData) =>
  instacne.post(`/menu/create`, {
    ...umsMenu,
  });
//修改后台菜单
export const updateMenu = (id: number, umsMenu: MenuData) =>
  instacne.post(`/menu/update/${id}`, {
    ...umsMenu,
  });
